package chapter2

object demo1_operation {
  def main(args: Array[String]): Unit = {
    // 1.算术运算符
    val result1:Int = 10/3
    println(result1) // 不能整除，取整数部分
    val result2 = 10/3
    println(result2)
    val result3:Double = 10/3
    val result4:Double = 10.toDouble/3
    val result5:Double = 10.0/3
    println(result3)
    println(result4)
    println(result5)

    // 2.比较运算符
    val a1 = 10
    val b1 = 12
    println(a1>b1)
    println(a1==b1)
    println(a1.equals(b1))
    //the result type of an implicit conversion must be more specific than AnyRef
    //println(a1.eq(b1)) //置右anyref才能用eq进行比较，比较的是地址
    println("========")
    val s1 = "hello" //放在常量池
    val s2 = new String("hello") //放在堆内存
    val s3 = "hello"
    println(s1 == s2)
    println(s1.==(s2))
    println(s1.equals(s2))
    println(s1.eq(s2))
    println(s1.eq(s3))
    println("========")
    // 3.逻辑运算符
    val n = 1
    println((6>5)&& n>0)
    println((6>5)&& n<0)

    println("========")
    // 4.赋值运算符
    var a = 10
    a += 10
    a %= 3
    println(a)

    println("========")
    // 5.位运算
    val a2 = 60 //转成二进制，按位与
    val b2 = 13
    println(a2&b2)

    println("========")
    // 6.运算的本质
    val a3 = 12
    val b3 = 27
    println(a3+b3)
    println(a3.+(b3)) //+号本质上是一个方法
  }
}
